package com.haipumi.actions;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.haipumi.ThreadPool.ThreadPool;
import com.haipumi.beans.JsonModel;
import com.opensymphony.xwork2.ActionSupport;

public class PhotoUploadAction extends ActionSupport{

	private static final long serialVersionUID = 8380205009487848642L;
	
	private JsonModel jm;
	
	// 注意，file并不是指前端jsp上传过来的文件本身，而是文件上传过来存放在临时文件夹下面的文件
	private List<File> newfphoto;
	// 提交过来的file的名字
	private List<String> newfphotoFileName;
	// 提交过来的file的MIME类型
	private List<String> newfphotoContentType;
	
	@Override
	public String execute(){
		//放在线程里面的话  可能因为线程没有运行完,所以就还没setPhoto,会导致student的photo属性为空
		String filesName="";//文件名
		String genFileName="";
		List<String> newFileName=new ArrayList<String>();//存放自动生成图片名称的集合
		for(int i=0;i<newfphoto.size();i++){
			genFileName=i+"-"+new Date().getTime()+newfphotoFileName.get(i);//使图片的名称各不相同

			filesName+=genFileName;//暂时是一张图片,所以不拼接+",";//给用户返回的图片名称,因为考虑到多图片上传,所以用,拼接
			newFileName.add(genFileName);
		}
		ThreadPool.getInstance().process( newfphoto, newFileName );
		//开启一个线程处理图片的上传
		
		jm=new JsonModel();
		jm.setCode(1);
		jm.setObj(filesName);
		return "success";
	}

	public JsonModel getJm() {
		return jm;
	}

	public void setJm(JsonModel jm) {
		this.jm = jm;
	}

	public List<File> getNewfphoto() {
		return newfphoto;
	}

	public void setNewfphoto(List<File> newfphoto) {
		this.newfphoto = newfphoto;
	}

	public List<String> getNewfphotoFileName() {
		return newfphotoFileName;
	}

	public void setNewfphotoFileName(List<String> newfphotoFileName) {
		this.newfphotoFileName = newfphotoFileName;
	}

	public List<String> getNewfphotoContentType() {
		return newfphotoContentType;
	}

	public void setNewfphotoContentType(List<String> newfphotoContentType) {
		this.newfphotoContentType = newfphotoContentType;
	}

}
